package org.itcast.dynamicdatasource.controller;

import org.itcast.dynamicdatasource.annotation.DDS;
import org.itcast.dynamicdatasource.pojo.Friend;
import org.itcast.dynamicdatasource.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    //  查询主库
    @PostMapping("/t1")
    public List<Friend> findDatas() {
        return friendService.findDatas();
    }

    //  查询从库
    @DDS("slave")
    @PostMapping("/t2")
    public List<Friend> findDatas2() {
        return friendService.findDatas();
    }

    //    查询主从库数据
    @PostMapping("/t3")
    public List<Friend> findDatas3() {
//         主库数据
        List<Friend> masterDatas = friendService.findDatas();
//        从库数据
        List<Friend> slaveDatas =friendService.findSlaveDatas();

        masterDatas.addAll(slaveDatas);
        System.out.println(masterDatas);
        return masterDatas;
    }
}
